export function isWeixin () {
	let ua = window.navigator.userAgent.toLowerCase();
    if(ua.match(/MicroMessenger/i) == 'micromessenger'){
        return true;
    } else {
        return false;
    }
}

export function ScolledBottom (element) {
	return element.scrollHeight - element.scrollTop === element.clientHeight;
}

export function compressImage (img, width = null, height = null, quality = 0.9) {
	console.log(img);
	let canvas = document.createElement('canvas');
	canvas.width = width || img.width;
	canvas.height = height || img.height;
	let ctx = canvas.getContext('2d');
	console.log(canvas.height);
	console.log(canvas.width);
	ctx.drawImage(img, 0, 0, canvas.width, canvas.height);
	return canvas.toDataURL('image/png', quality);
}

/**
 * 判断元素是否在可视区域内
 * @param DOMElement element
 */
export function isDomInView(element)
{
	let clientRect = element.getBoundingClientRect();
	let clientHeight = document.documentElement.clientHeight;
	let scrollOffset = window.scrollY;

	return clientHeight + scrollOffset > clientRect.top && clientHeight + scrollOffset < clientRect.top + clientRect.height;
}
